#ifndef NR_SCHEDULER_MANAGER_H
#define NR_SCHEDULER_MANAGER_H

#include "nr_std.h"
#include "nr_scheduler.h"
#include "nr_device_item_manager.h"
#include "nr_channel_manager.h"
#include "nr_io_manager.h"
#include "nr_manager_base.h"

class nr_scheduler_manager : 
    public nr_manager_base , 
    public nr_channel_output_delegate
{
    Q_OBJECT
public:
    nr_scheduler_manager(nr_device_item_manager& item_manager,
        nr_channel_manager& channel_manager, nr_io_manager& io_manager);

    virtual ~nr_scheduler_manager();
    
    nr_error_t load();

    nr_error_t unload();
    
    nr_error_t add_scheduler(const QString& name, nr_scheduler* scheduler);
    
    void remove_scheduler(const QString& name);

    nr_schedulers& schedulers() { return m_schedulers; } 
    
    nr_error_t set_active_scheduler(const QString& name);

    nr_error_t set_active_scheduler(nr_scheduler* scheduler);

    nr_scheduler* active_scheduler();
    
    virtual void on_data(nr_data *data);
    
    virtual void on_event(nr_event *evt);
    
private:
    nr_error_t record_on();
    nr_error_t record_off();

    void start_item(nr_device_item *item);

    void start_group(nr_device_group *group);

    nr_schedulers m_schedulers;
    nr_scheduler* m_active_scheduler;
    QTimer m_scheduler_timer;
    nr_device_item_manager &m_item_manager;
    nr_channel_manager &m_channel_manager;
    nr_io_manager &m_io_manager;
    QList<nr_channel_output*> m_output_channels;

    bool m_is_record_on;
        
private slots:
    void on_scheduler_timer();
};

#endif // NR_SCHEDULER_RECORD_H
